//
//  Singleton.h
//  Day8
//
//  Created by wenjim on 17/10/26.
//  Copyright © 2017年 WenJim. All rights reserved.
//

// 以后就可以使用 interfaceSingleton 来替代后面的方法声明
#define interfaceSingleton(name) +(instancetype)share##name;

#if __has_feature(objc_arc)
// ARC
#define implementationSingleton(name)  \
+ (instancetype)share##name   \
{            \
name * instance = [[self alloc] init]; \
return instance; \
} \
static name * _instance = nil;\
+ (instancetype)allocWithZone:(struct _NSZone *)zone\
{\
static dispatch_once_t onceToKen;  \
dispatch_once(&onceToKen, ^{   \
_instance = [[super allocWithZone:zone] init]; \
}); \
return _instance; \
} \
-(id)copyWithZone:(NSZone *)zone \
{ \
return _instance;\
}\
-(id)mutableCopyWithZone:(NSZone *)zone \
{ \
return _instance;\
}\


#else
// MRC
#define implementationSingleton(name)  \
+ (instancetype)share##name   \
{            \
name * instance = [[self alloc] init]; \
return instance; \
} \
static name * _instance = nil;\
+ (instancetype)allocWithZone:(struct _NSZone *)zone\
{\
static dispatch_once_t onceToKen;  \
dispatch_once(&onceToKen, ^{   \
_instance = [[super allocWithZone:zone] init]; \
}); \
return _instance; \
} \
-(id)copyWithZone:(NSZone *)zone \
{ \
return _instance;\
}\
-(id)mutableCopyWithZone:(NSZone *)zone \
{ \
return _instance;\
}\
- (oneway void)release\
{\
}\
-(instancetype)retain\
{\
return _instance;\
}\
- (NSUInteger)retainCount\
{\
return MAXFLOAT; \
} \

#endif




#ifndef Singleton_h
#define Singleton_h


#endif /* Singleton_h */
